package com.rsjgroup.water.controller;

import com.rsjgroup.water.pojo.User;
import com.rsjgroup.water.service.IUserService;
import com.rsjgroup.water.service.exception.updateException;
import com.rsjgroup.water.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/users")
public class UserController extends BaseController {

    @Autowired
    private IUserService userService;

    @PostMapping("/updateAvatar")
    public JsonResult<Void> updateAvatar(@RequestBody User user) {
        Integer uid = 1;
        user.setUid(uid);   //假数据，后期用session实现
        userService.updateAvatar(user);
        JsonResult<Void> jsonResult = new JsonResult<>();
        jsonResult.setState(OK);
        jsonResult.setMessage("更新头像成功");
        return jsonResult;
    }

    @RequestMapping("/updateUsername")
    public JsonResult<Void> updateUsername(@RequestBody User user) {
        Integer uid = 1;
        user.setUid(uid);   //假数据，后期用session实现
        userService.updateUsername(user);
        JsonResult<Void> jsonResult = new JsonResult<>();
        jsonResult.setState(OK);
        jsonResult.setMessage("更换名称成功");
        return jsonResult;
    }
}
